<?php
if(!defined('DCS_ROOT')) {exit('Access Denied');}

class main {

	function __construct() {
		$this->defaultAction();
		exit();
	}

	function defaultAction(){
		session_start();
		if(isPost()) {

			if (empty($_SESSION['verifycode']) || trim(strtolower($_POST['verifycode'])) != $_SESSION['verifycode']) {
				message('验证码错误！','/reg');
			}

			$tpl = new Template("accounts/reg.htm");
			$username = trim($_POST["username"]);
			$email = trim($_POST["email"]);
			$password = trim($_POST["password"]);
			if(preg_match('/^.+$/',$username) and  preg_match('/^.+$/',$email) and  preg_match('/^.+$/',$password) ){
				require_once(APP_PATH."model/accounts.php" );
				$DB  = getDB();
				$data	=  new accountsModel($DB);
				$reg	= $data->regUser($username,$email,$password);
				if($reg == 'no'){
					message('用户注册失败！','/reg');
				}elseif($reg){
					message('','/login');				
					exit();
				}else{
					$message = '用户注册失败';
				}
			}else{
				$message = '请输入用户名、邮箱或密码。';
			}
			message($message);
		}else{	
			$username = getMember('uid');
			if(!empty($username)){
				message('','/accounts');
			}
			$tpl = new Template("accounts/reg.htm");
			$tpl->assign(assignUser());
			$tpl->output();
		}
	}


}

?>
